﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Exam.Repository.Interface
{
    public interface IRepository<T> where T :class,new()
    {
        /// <summary>
        /// 条件查询
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        IQueryable<T> QueryAll(Expression<Func<T, bool>>? where);

        Task<IQueryable<T>> QueryAllAsync(Expression<Func<T, bool>>? where);
        /// <summary>
        /// 分组查询
        /// </summary>
        /// <typeparam name="type"></typeparam>
        /// <param name="order"></param>
        /// <param name="IsAsc"></param>
        /// <param name="where"></param>
        /// <returns></returns>
        IQueryable<T> QueryAll<type>(Expression<Func<T,type>> order ,bool IsAsc=true,Expression<Func<T, bool>>? where=null);

        Task<IQueryable<T>> QueryAllAsync<type>(Expression<Func<T, type>> order, bool IsAsc = true, Expression<Func<T, bool>>? where = null);
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <typeparam name="type"></typeparam>
        /// <param name="total"></param>
        /// <param name="skip"></param>
        /// <param name="take"></param>
        /// <param name="order"></param>
        /// <param name="IsAsc"></param>
        /// <param name="where"></param>
        /// <returns></returns>
        IQueryable<T> QueryAll<type>(out int total,int skip,int take,Expression<Func<T, type>> order,bool IsAsc=true,Expression<Func<T,bool>>? where=null);

        Task<IQueryable<T>> QueryAllAsync<type>(int skip, int take, Expression<Func<T, type>> order, bool IsAsc = true, Expression<Func<T, bool>>? where = null);
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="t"></param>
        void Add(T t);
        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="ie"></param>
        void AddRange(IEnumerable<T> ie);
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="t"></param>
        void Delete(T t);
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="ie"></param>
        void DeleteRange(IEnumerable<T> ie);
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="t"></param>
        void Update(T t);
        /// <summary>
        /// 批量修改
        /// </summary>
        /// <param name="ie"></param>
        void UpdateRange(IEnumerable<T> ie);
        /// <summary>
        /// 保存
        /// </summary>
        /// <returns></returns>
        int SaveChanges();

        Task<int> SaveChangesAsync();

    }
}
